import requests
import execjs

cookies = {
    'HMACCOUNT': '9F47B428D92F550C',
    'Hm_lvt_9bcbda9cbf86757998a2339a0437208e': '1720709647',
    'no-alert3': 'true',
    'tk': '601100958127505223',
    'sessionid': '1r4gcnrvb338naa18vz7nb8dwuax270r',
    'Hm_lvt_c99546cf032aaa5a679230de9a95c7db': '1720709646,1720793980',
    'Hm_lpvt_9bcbda9cbf86757998a2339a0437208e': '1720952565',
    'Hm_lpvt_c99546cf032aaa5a679230de9a95c7db': '1720952568',
}

headers = {
    'authority': 'match.yuanrenxue.cn',
    'accept': 'application/json, text/javascript, */*; q=0.01',
    'accept-language': 'zh-CN,zh;q=0.9',
    # 'cookie': 'Hm_lvt_c99546cf032aaa5a679230de9a95c7db=1720709646; HMACCOUNT=9F47B428D92F550C; Hm_lvt_9bcbda9cbf86757998a2339a0437208e=1720709647; no-alert3=true; tk=601100958127505223; sessionid=1r4gcnrvb338naa18vz7nb8dwuax270r; Hm_lpvt_9bcbda9cbf86757998a2339a0437208e=1720793414; m=6d5c69169dbe940a4993de006d80a46d|1720793614000; Hm_lpvt_c99546cf032aaa5a679230de9a95c7db=1720793615',
    'referer': 'https://match.yuanrenxue.cn/match/2',
    'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"macOS"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-origin',
    'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
    'x-requested-with': 'XMLHttpRequest',
}

params = {
    'page': '5',
}

f = open('getm.js', 'r', encoding='utf-8')
js = f.read()
ctx = execjs.compile(js)

rst = 0

for i in range(1, 6):
    m = ctx.call('get_m')
    cookies['m'] = m

    params['page'] = str(i)
    response = requests.get('https://match.yuanrenxue.cn/api/match/2', cookies=cookies, params=params, verify=False).json()
    if response['state'] != "success":
        continue
    data = response['data']
    for v in data:
        rst += v['value']

f.close()
print(rst)
